package grails.coherence.enhancer.cacheloader;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.tangosol.net.cache.AbstractCacheLoader;

/**
 * Simple cache loader that retrieves cache values from underlying domain instances. 
 * 
 * @author Massimiliano Mazzarolo
 *
 */
class GormCacheLoader extends AbstractCacheLoader implements ApplicationContextAware {
	
	ApplicationContext applicationContext
	
	String className
	
	def load(key) {
		log "Loading ${className}[$key]"
		domainClass?.get(key)
	}
	
	private def getDomainClass() {				
		applicationContext.getBean("${className}PersistentClass")
	}
}
